"use server"
import QuestionCard from "@/components/question-card"
import { getQuestionVOById } from "@/api/question"
import "./index.css"

interface Props {
  params: {
    questionId: number // 题目ID
  }
}

/**
 * 题目详情页
 */
export default async function QuestionPage({ params }: Props) {
  const { questionId } = params

  let question: QuestionVO | null = null

  try {
    const res = await getQuestionVOById({
      id: questionId
    })
    question = res.data
  } catch (error) {
    console.error("获取题目详情失败，" + error)
  }

  if (!question) {
    return <div>获取题目详情失败，请刷新重试</div>
  }

  return (
    <div id="question-page" className="max-width-content">
      <QuestionCard question={question} />
    </div>
  )
}
